#include <bits/stdc++.h>
using namespace std;

struct HLD{ // 重链剖分

using llt = long long;

/// 树结构, 1-index
vector<vector<int>> g;
/// 点权值
vector<llt> weight;

/// 建单向边
void mkDiEdge(int a, int b){
    g[a].push_back(b);
}
/// 建双向边
void mkBiEdge(int a, int b){
    mkDiEdge(a, b); mkDiEdge(b, a);
}

/// 树链剖分结构
struct node_t{
    int parent; // 父节点
    int hson;   // 重儿子
    int depth;  // 该节点的深度, 根节点深度为0
    int size;   // 本节点所领子树的节点总数
    int top;    // 本节点所在重链的顶
    int nid;    // 本节点在线段树中的编号
    int mdes;   // 本节点所领子树的线段树编号均在[nid, mdes]中
};

int root; // 树根
vector<int> nid2old; // nid2old[i]表示线段树中第i个节点在原树中的编号
int timestamp; // 辅助变量
vector<node_t> nodes;

/// 递归找重边
void _dfsHeavyEdge(int u, int p, int d){
    auto & n = nodes[u];
    n.parent = p;
    n.depth = d;
    n.size = 1;

    for(auto v : g[u]){
        if(v == p) continue;
        _dfsHeavyEdge(v, u, d + 1);
        n.size += nodes[v].size;
        if(nodes[n.hson].size < nodes[v].size) n.hson = v;
    }
    return;
}

/// 递归找重链
void _dfsHeavyPath(int u, int top){
    auto & n = nodes[u];
    n.top = top;
    nid2old[n.mdes = n.nid = ++timestamp] = u;

    if(0 == n.hson) return;
    _dfsHeavyPath(n.hson, top);
    n.mdes = max(n.mdes, nodes[n.hson].mdes);

    for(auto v : g[u]){
        if(v != n.parent and v != n.hson){
            _dfsHeavyPath(v, v);
            n.mdes = max(n.mdes, nodes[v].mdes);
        }
    }
    return;
}


/// 初始化, n是树的点数
void init(int n){
    timestamp = 0;
    /// 初始化树结构
    g.assign(n + 1, {});
    weight.assign(n + 1, 0);
    /// 初始化树链结构
    nodes.assign(n + 1, {0, 0, 0, 0, 0, 0, 0});
    nid2old.assign(n + 1, 0); 
}

/// 在输入所有数据以后构建
void build(int root, int n){
    /// 建树链
    _dfsHeavyEdge(this->root = root, 0, 0);
    _dfsHeavyPath(root, root);
}

/// 求原树上x和y的LCA
int lca(int x, int y){
    while(nodes[x].top != nodes[y].top){
        if(nodes[nodes[x].top].depth < nodes[nodes[y].top].depth) y = nodes[nodes[y].top].parent;
        else x = nodes[nodes[x].top].parent;
    }
    return nodes[x].depth <= nodes[y].depth ? x : y;
}

}St;


int N, M, S;

int main(){
#ifndef ONLINE_JUDGE
    freopen("z.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> N >> M >> S;
    St.init(N);
    for(int a,b,i=1;i<N;++i){
        cin >> a >> b;
        St.mkBiEdge(a, b);
    }
    St.build(S, N);
    for(int x,y,i=0;i<M;++i){
        cin >> x >> y;
        cout << St.lca(x, y) << endl;
    }
    return 0;
}